package com.xms.consumers.logging;

import com.xms.logging.service.IEntityLogService;
import com.xms.sdk.core.OwnerObject;
import com.xms.sdk.event.EntityAssignedEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 实体分派后执行日志记录
 * </p>
 *
 * @author migo
 * @since 2021/9/29
 */
@Service
public class LoggingOnEntityAssigned {
    private IEntityLogService _entityLogService;

    @Autowired
    public LoggingOnEntityAssigned(com.xms.logging.service.IEntityLogService entityLogService) {
        _entityLogService = entityLogService;
    }

    @Async
    @EventListener
    public void handleEvent(EntityAssignedEvent eventMessage) {
        if (eventMessage.EntityMetadata.getLogenabled()) {
            _entityLogService.assignedLog(eventMessage.Data, (OwnerObject) eventMessage.OriginData.get("ownerid"), (OwnerObject) eventMessage.Data.get("ownerid"), eventMessage.EntityMetadata);
        }
    }
}
